﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace MarioArena
{
    public static class Settings
    {
        public static string Name = "Unnamed";
        public static string WebID = "";
        public static string IPAddress = "127.0.0.1";
        public static int Port = 6789;
        public static int RespawnTime = 30;

        /// <summary>
        /// The jump distance of the player from standstill to the middle of the jump (in mid-air)
        /// measured in amount of tiles, the tile which is being stood on excluded. Used for AI.
        /// Maximum distance of the jump from standing still = 9;
        /// </summary>
        public static int JumpDistance = 4;
        /// <summary>
        /// The jump height of the player measured in amount of tiles. Used for AI.
        /// </summary>
        public static int JumpHeight = 5;

        public static bool LaunchedWithArguments = false;
        public static string gameDataFolder = "\\MarioArena";
        public static string gameDataFile = "\\gamedata.txt";


        /// <summary>
        /// Validates the applicationdata.
        /// </summary>
        public static void ValidateApplicationData()
        {
            string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string marioArenaFolder = appDataPath + gameDataFolder;
            //Check if directory exists
            if (!Directory.Exists(marioArenaFolder))
            {
                //if not, create the directory and add a new gamedata file.
                Directory.CreateDirectory(marioArenaFolder);
            }
            CreateGameDataFile(marioArenaFolder);
        }

        /// <summary>
        /// Creates/overwrites the game data file.
        /// </summary>
        /// <param name="folderPath">Path to folder where the game data should be stored (appdata/marioarena).</param>
        private static void CreateGameDataFile(string folderPath)
        {
            try
            {
                string executablePath = Application.ExecutablePath;
                string gameData = "\"\" \"" + executablePath + "\""; //"" "exepath"
                File.WriteAllText(folderPath + "\\gamedata.txt", gameData);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
